#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
class Solution
{
public:
    vector<int> relativeSortArray(vector<int> &arr1, vector<int> &arr2)
    {
        // 按照arr2 的顺序获取权重
        unordered_map<int, int> p_map;
        for (int i = 0; i < arr2.size(); i++)
            p_map[arr2[i]] = arr2.size() - i;
        // 按照权重排序 权重为0就为升序
        sort(arr1.begin(), arr1.end(), [&](int a, int b) -> bool
             { return p_map[a] == p_map[b] ? a < b : p_map[a] > p_map[b]; });
        return arr1;
    }
};